// pages/member//distribution/myInvitation/list.js
import {memberList} from '../../../../api/member'
import {
  getInfo
} from '../../../../api/mch'
const util = require('../../../../utils/util.js')
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 0,
    status:0,
    mch:{},
    pageNum:1,
    swiperHeight: '600rpx',
    myInvitation: []
  },
loadMch(){
  var _this = this;
  getInfo(app.globalData.mchId).then(res => {
    _this.data.mch = res.data;
    _this.setData({
      mch:_this.data.mch
    })
  });
},

loadMemberList(){
  this.loadMch()
  if(this.data.pageNum==1){
    this.data.myInvitation=[]
  }
  memberList({
    status:this.data.status,
    pageNum:this.data.pageNum,
    pageSize:20,
  }).then(res=>{
    this.data.swiperHeight='height:'+((res.data.data.length* 170)+140)+'rpx'
    res.data.data.forEach(item=>{
     
      if(!util.isNull(item.avatar)){

        item.avatar=util.thumbnail(item.avatar,100,100)
      }else{
        item.avatar=this.data.mch.logo
      }
      item.createDate=util.datetimeFormat(item.createDate)
    
    })
    
    res.data.data.forEach(item=>{
      this.data.myInvitation.push(item)
     
    })
   
    this.setData({
      myInvitation: this.data.myInvitation,
      swiperHeight: this.data.swiperHeight
    })

  })
},

reachBottom(){
  console.log('2222')
  this.data.pageNum+=1
  this.loadMemberList()
},

  bindChange: function (e) {
    var that = this;
    console.log(e)
    this.data.myInvitation=[]
    this.data.pageNum=1
    that.setData({
      myInvitation:this.data.myInvitation,
      status:e.detail.current,
      currentTab: e.detail.current
    });
    this.loadMemberList()
  },
  //  tab切换逻辑
  swichNav: function (e) {
    this.data.pageNum=1
    this.data.myInvitation=[]
    console.log(e)
    var that = this;

    if (this.data.currentTab === e.currentTarget.dataset.current) {
      return false;
    } else {
      that.setData({
        myInvitation:this.data.myInvitation,
        status:e.currentTarget.dataset.current,
        currentTab: e.currentTarget.dataset.current
      })
      // this.loadMemberList()
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.loadMemberList()
 
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
   
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})